function Ajax(options) {
    options = Object.assign({
        baseURL: 'http://127.0.0.1:4000',
        method: "POST",
        path: '/',
        progress: Function.prototype
    }, options);
    return new Promise((resolve, reject) => {
        //创建xhr
        let xhr = new XMLHttpRequest;
        //进度条
        xhr.upload.onprogress = options.progress;
        xhr.open(options.method, options.baseURL + options.path);
        xhr.send(options.data);
        //回调
        xhr.onreadystatechange = () => {
            // if (xhr.readyState !== 4 &&)
            if (xhr.readyState === 4) {
                if (/^(2|3)\d{2}$/.test(xhr.status)) {
                    resolve(JSON.parse(xhr.responseText));
                } else {
                    reject(xhr);
                }
            }
        }

    })
}

// 文件名
function getFileName(file) {
    let suffix = md5(file) + new Date().getTime();
    let index = file.name.lastIndexOf('.');
    let fileName = `${suffix}${file.name.slice(index)}`;
    return {
        suffix,
        fileName
    }
}